package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
public class UserController {

    //使用注解的value属性来指定接收请求参数
    //localhost:8080/user/login?username=songge&password=niupi
    @RequestMapping("user/login")
    public BaseRespVo login(@RequestParam("username") String usernamex,
                            @RequestParam("password") String passwordy) {
        return BaseRespVo.ok();
    }

    //使用字符串或字符串数组来接收
    //数组的话，会使用逗号作为分隔符
    @RequestMapping("header")
    public BaseRespVo header(@RequestHeader("Accept") String[] accept,
                             @RequestHeader("Host") String host) {
        return BaseRespVo.ok();
    }

    @RequestMapping("cookie")
    public BaseRespVo cookie(@CookieValue("songge") String value) {
        return BaseRespVo.ok(value);
    }

    @RequestMapping("session/put/{value}")
    public BaseRespVo put(HttpSession session,@PathVariable("value")String value) {
        session.setAttribute("monday",value);
        return BaseRespVo.ok();
    }

    //对应的值的类型是Object，取决于你放入的时候的数据类型
    @RequestMapping("session/get")
    /*public BaseRespVo get(HttpSession session) {
        Object money = session.getAttribute("monday");*/
    public BaseRespVo get(@SessionAttribute("monday") String monday) {
        return BaseRespVo.ok();
    }
}
